package com.powermanager.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.powermanager.R;
import com.powermanager.adapter.TimeTypeAdapter;
import com.powermanager.bean.DayBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by lqy on 16/7/6.
 */
public class TimeTypeActivity extends BaseActivity {
    @Bind(R.id.mIvOnce)
    ImageView mIvOnce;
    @Bind(R.id.mLayoutOnce)
    LinearLayout mLayoutOnce;
    @Bind(R.id.mIvEveryday)
    ImageView mIvEveryday;
    @Bind(R.id.mLayoutEveryday)
    LinearLayout mLayoutEveryday;
    @Bind(R.id.mRvDisplay)
    RecyclerView mRvDisplay;
    TimeTypeAdapter adapter;
    ArrayList<DayBean> selected = new ArrayList<>();
    @Bind(R.id.mBtnOk)
    Button mBtnOk;
    @Bind(R.id.mBtnCancle)
    Button mBtnCancle;
    public boolean isHead = true;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_timertype);
        ButterKnife.bind(this);
        mRvDisplay.setLayoutManager(new LinearLayoutManager(this));
        adapter = new TimeTypeAdapter(TimeTypeActivity.this);
        mRvDisplay.setAdapter(adapter);
        selected = adapter.getSelected();
        onClick(mLayoutOnce);
    }

    @OnClick({R.id.mLayoutOnce, R.id.mLayoutEveryday,R.id.mBtnOk, R.id.mBtnCancle})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.mLayoutOnce:
                isHead = true;
                selected.clear();
                selected.add(new DayBean(-1,"执行一次"));
                mIvEveryday.setSelected(false);
                mIvOnce.setSelected(true);
                adapter.notifyDataSetChanged();
                break;
            case R.id.mLayoutEveryday:
                isHead = true;
                selected.clear();
                selected.add(new DayBean(-1,"每天"));
                mIvEveryday.setSelected(true);
                mIvOnce.setSelected(false);
                adapter.notifyDataSetChanged();
                break;
            case R.id.mBtnOk:
                Intent intent = new Intent();
                if (isHead){
                    intent.putParcelableArrayListExtra("data",selected);

                }else
                intent.putParcelableArrayListExtra("data",adapter.getSortedResult());
                setResult(RESULT_OK,intent);
                finish();
                break;
            case R.id.mBtnCancle:
                break;
        }
    }

    public void resetList() {
        isHead = false;
        mIvEveryday.setSelected(false);
        mIvOnce.setSelected(false);
    }


}
